import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/** note: submenu only apppear when children.length>=1
*   detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
**/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/authredirect', component: () => import('@/views/login/authredirect'), hidden: true },
  { path: '/404', component: () => import('@/views/errorPage/404'), hidden: true },
  { path: '/401', component: () => import('@/views/errorPage/401'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: '测试目录',
        meta: { title: '测试目录', icon: 'dashboard', noCache: true }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  { path: '*', redirect: '/404', hidden: true },
  // 账号管理
  {
    path: '/account',
    component: Layout,
    redirect: '/account/list',
    meta: { title: '账号管理', icon: 'component', noCache: true },
    children: [
      {
        path: 'list',
        component: () => import('@/views/account/list'),
        name: '账号列表',
        meta: { title: '账号列表' }
      },
      {
        path: 'manage',
        component: () => import('@/views/account/manage'),
        name: '角色管理',
        meta: { title: '角色管理' }
      }
    ]
  },
  // 消息管理
  {
    path: '/message',
    component: Layout,
    redirect: '/message/list',
    meta: { title: '消息管理', icon: 'component' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/message/list'),
        name: '公告列表',
        meta: { title: '公告列表' }
      },
      {
        path: 'notice',
        component: () => import('@/views/message/notice'),
        name: '公告发布',
        meta: { title: '公告发布' }
      }
    ]
  },
  // 系统配置
  {
    path: '/system',
    component: Layout,
    redirect: '/system/shop',
    meta: { title: '系统配置', icon: 'component' },
    alwaysShow: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/system/shop'),
        name: '商品折扣',
        meta: { title: '商品折扣' }
      }
    ]
  },
  // 商品管理
  {
    path: '/commodity',
    component: Layout,
    redirect: '/commodity/list',
    meta: { title: '商品管理', icon: 'component' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/commodity/list'),
        name: '商品类目',
        meta: { title: '商品类目' }
      },
      {
        path: 'search',
        component: () => import('@/views/commodity/search'),
        name: '商品查询',
        meta: { title: '商品查询' }
      },
      {
        path: 'add',
        component: () => import('@/views/commodity/add'),
        name: '商品新增',
        meta: { title: '商品新增' }
      },
      {
        path: 'stock',
        component: () => import('@/views/commodity/stock'),
        name: '库存管理',
        meta: { title: '库存管理' }
      },
      {
        path: 'around',
        component: () => import('@/views/commodity/around'),
        name: '前后台类别匹配',
        meta: { title: '前后台类别匹配' }
      }
    ]
  },
  // 订单管理
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    meta: { title: '订单管理', icon: 'component' },
    alwaysShow: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/order/list'),
        name: '订单列表',
        meta: { title: '订单列表' }
      },
      {
        path: 'detail',
        component: () => import('@/views/order/detail'),
        name: '订单详情',
        meta: { title: '订单详情' }
      }
    ]
  },
  // 活动管理
  {
    path: '/activity',
    component: Layout,
    redirect: '/activity/banner',
    meta: { title: '活动管理', icon: 'component' },
    alwaysShow: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/activity/banner'),
        name: 'banner维护',
        meta: { title: 'banner维护' }
      },
      {
        path: 'setting',
        component: () => import('@/views/activity/setting'),
        name: '秒杀活动设置',
        meta: { title: '秒杀活动设置' }
      }
    ]
  },
  // 报表管理
  {
    path: '/form',
    component: Layout,
    redirect: '/form/list',
    meta: { title: '报表管理', icon: 'component' },
    alwaysShow: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/form/list'),
        name: '内购销售报表',
        meta: { title: '内购销售报表' }
      }
    ]
  }
]
